package model

import (
	"gorm.io/gorm"
)

type File struct {
	gorm.Model
	FileField
}

const (
	File_Table = "files"
	File_Sid   = "sid"
	File_Name  = "name"
	File_Size  = "size"
	File_Link  = "link"
	File_Type  = "type"
)

type FileField struct {
	Sid  Sid    `json:"sid"`
	Name string `json:"name"`
	Size int64  `json:"size"`
	Link string `json:"link"`
	Type string `json:"type"`
}

func (f *File) Create(db *gorm.DB) error {
	return db.Create(f).Error
}

func (f *File) Get(db *gorm.DB) error {
	return db.Where(File_Sid, f.Sid).First(f).Error
}

func (f *File) Delete(db *gorm.DB) error {
	return db.Where(File_Sid, f.Sid).Delete(f).Error
}
